package com.s.rpc.customer;

import com.s.rpc.core.NettyClient;
import com.s.rpc.serializer.Serializer;
import com.s.rpc.utils.JsonSerializer;

import java.util.concurrent.CompletableFuture;

/**
 * @author ShenshenLuo
 * @email luoshenshen@buaa.edu.cn
 * @date 2025/5/11 15:11
 **/
public class RunClient {

    public static void main(String[] args) throws Exception {
        Serializer serializer = new JsonSerializer();
        NettyClient client = new NettyClient("localhost", 8080, serializer);
        client.startClient();

        try {
            CompletableFuture<Integer> result = client.invoke(
                    "com.s.rpc.provider.HelloWorld",
                    "hello",
                    new Class<?>[]{String.class},
                    new Object[]{"client"});

            result.thenAccept(sum -> System.out.println("Result: " + sum))
                    .exceptionally(e -> {
                        System.err.println("Error: " + e.getMessage());
                        return null;
                    })
                    .get(); // 等待结果
        } finally {
            client.close();
        }
    }
}
